package com.xcdh.trading.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xcdh.trading.entity.GpHistoryName;
import com.xcdh.trading.mapper.GpHistoryNameMapper;
import com.xcdh.trading.response.TradingRes;
import com.xcdh.trading.service.GpHistoryNameService;
import com.xcdh.trading.util.TuShareApi;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 股票历史名称服务实现类，继承ServiceImpl实现具体业务逻辑
 */
@Service
public class GpHistoryNameServiceImpl extends ServiceImpl<GpHistoryNameMapper, GpHistoryName> implements GpHistoryNameService {
    // 可在此实现自定义业务逻辑方法
    @Override
    public void syncGpHistoryName(){
        TradingRes tradingRes = TuShareApi.post("namechange");
        List<GpHistoryName> historyNameList = tradingRes.parse(GpHistoryName.class);
        for (GpHistoryName historyName : historyNameList) {
            GpHistoryName gpHistoryName = lambdaQuery()
                    .eq(GpHistoryName::getName, historyName.getName())
                    .eq(GpHistoryName::getTsCode, historyName.getTsCode()).one();
            if(gpHistoryName == null){
                save(historyName) ;
            }
        }
    }
}
